home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / intuisup.lha / Intuisup / source.lha / Editor / screen.c < prev    next >
C/C++ Source or Header  |  1992-10-05  |  11KB  |  379 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1992 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: screen.c
  6.  *    Created ..: Friday 02-Oct-92 10:31:18
  7.  *    Revision .: 1
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    02-Oct-92   Michael Bjerking       New realese, better Screen/Window editor
  12.  *    02-Oct-92   Michael Bjerking       Created this file!
  13.  *
  14.  * $Revision Header ********************************************************/
  15.  
  16. /* Includes */
  17.  
  18. #include "includes.h"
  19. #include "defines.h"
  20. #include "imports.h"
  21. #include "protos.h"
  22.  
  23. /* Screen data */
  24.  
  25. struct NewScreen editor_new_screen =
  26. {
  27.     0,                            /* LetfEdge (not used) */
  28.     0,                            /* TopEdge */
  29.     320,                        /* Width  (320=Low, 640=High resolution) */
  30.     200,                        /* Height (200=non ->  400=interlace) */
  31.     2,                            /* Depth (1-6 => 2-64 colours) */
  32.     0,                            /* DetailPen */
  33.     1,                            /* BlockPen */
  34.     0,                            /* ViewModes - flags: HIRES, INTERLACE,
  35.                                                                                                                                         SPRITES, DUALPF, HAM */
  36.     CUSTOMSCREEN,                /* Type (CUSTOMSCREEN or CUSTOMBITMAP) */
  37.     NULL,                        /* Font (NULL or struct Textattr) */
  38.     (UBYTE *) & editor_screen_title[0],    /* DefaultTitle (NULL or NULL terminating string)*/
  39.     NULL,                        /* Gadgets (pointer to first gadget) */
  40.     NULL                        /* CustomBitap (pointer to BitMap) */
  41. };
  42. USHORT editor_screen_type = EDITOR_SCREEN_TYPE_WBENCH;
  43.  
  44. /* Data for fonts */
  45.  
  46. STATIC struct TextAttr screen_text_attr[]=
  47. {
  48.     {
  49.         (STRPTR) "topaz.font", 8, FS_NORMAL, FPF_ROMFONT
  50.     }
  51. };
  52.  
  53. /* Defines and data for gadgets */
  54.  
  55. #define SCREEN_GADGET_LEFTEDGE    0
  56. #define SCREEN_GADGET_TOPEDGE        1
  57. #define SCREEN_GADGET_WIDTH        2
  58. #define SCREEN_GADGET_HEIGHT        3
  59. #define SCREEN_GADGET_DEPTH        4
  60. #define SCREEN_GADGET_DETAILPEN    5
  61. #define SCREEN_GADGET_BLOCKPEN    6
  62. #define SCREEN_GADGET_INTERLACE    7
  63. #define SCREEN_GADGET_SPRITES        8
  64. #define SCREEN_GADGET_DUALPF        9
  65. #define SCREEN_GADGET_HIRES        10
  66. #define SCREEN_GADGET_HAM            11
  67. #define SCREEN_GADGET_TITLE        12
  68. #define SCREEN_GADGET_SCREENTYPE    13
  69. #define SCREEN_GADGET_OK            14
  70. #define SCREEN_GADGET_CANCEL        15
  71.  
  72. STATIC BYTE *screen_gadget14_text_array[]=
  73. {
  74.     "WBENCHSCREEN",
  75.     "CUSTOMSCREEN",
  76.     "CUSTOMBITMAP",
  77.     NULL
  78. };
  79. STATIC struct GadgetData screen_gadget_data[]=
  80. {
  81.     {
  82.         5, 65, 296, 4, 71, 14,
  83.         "LeftEdge ", &screen_text_attr[0],
  84.         {10, 0, (VOID *) 0}
  85.     },
  86.     {
  87.         5, 64, 296, 19, 71, 14,
  88.         "TopEdge  ", &screen_text_attr[0],
  89.         {10, 0, (VOID *) 0}
  90.     },
  91.     {
  92.         5, 64, 296, 34, 71, 14,
  93.         "Width    ", &screen_text_attr[0],
  94.         {10, 0, (VOID *) 320}
  95.     },
  96.     {
  97.         5, 64, 296, 49, 71, 14,
  98.         "Height   ", &screen_text_attr[0],
  99.         {10, 0, (VOID *) 200}
  100.     },
  101.     {
  102.         9, 64, 446, 80, 51, 12,
  103.         "Depth", &screen_text_attr[0],
  104.         {1, 6, (VOID *) 2}
  105.     },
  106.     {
  107.         5, 64, 296, 64, 71, 14,
  108.         "DetailPen", &screen_text_attr[0],
  109.         {10, 0, (VOID *) 0}
  110.     },
  111.     {
  112.         5, 64, 296, 79, 71, 14,
  113.         "BlockPen ", &screen_text_attr[0],
  114.         {10, 0, (VOID *) 1}
  115.     },
  116.     {
  117.         2, 64, 476, 19, 21, 11,
  118.         "INTERLACE", &screen_text_attr[0],
  119.         {0, 1, (VOID *) 0}
  120.     },
  121.     {
  122.         2, 64, 476, 34, 21, 11,
  123.         "SPRITES  ", &screen_text_attr[0],
  124.         {0, 1, (VOID *) 0}
  125.     },
  126.     {
  127.         2, 64, 476, 49, 21, 11,
  128.         "DUALPF   ", &screen_text_attr[0],
  129.         {0, 1, (VOID *) 0}
  130.     },
  131.     {
  132.         2, 64, 476, 4, 21, 11,
  133.         "HIRES    ", &screen_text_attr[0],
  134.         {0, 1, (VOID *) 0}
  135.     },
  136.     {
  137.         2, 64, 476, 64, 21, 11,
  138.         "HAM      ", &screen_text_attr[0],
  139.         {0, 1, (VOID *) 0}
  140.     },
  141.     {
  142.         4, 256, 36, 75, 110, 14,
  143.         "DefaultTitle", &screen_text_attr[0],
  144.         {20, 0, "Screen"}
  145.     },
  146.     {
  147.         3, 64, 21, 19, 138, 37,
  148.         "Screen Type:", &screen_text_attr[0],
  149.         {1, 0, &screen_gadget14_text_array[0]}
  150.     },
  151.     {
  152.         1, 16, 50, 95, 110, 15,
  153.         "_Ok", &screen_text_attr[0],
  154.         {0, 0, (VOID *) 0}
  155.     },
  156.     {
  157.         1, 16, 340, 95, 110, 15,
  158.         "_Cancel", &screen_text_attr[0],
  159.         {0, 0, (VOID *) 0}
  160.     },
  161.     {
  162.         INTUISUP_DATA_END
  163.     }
  164. };
  165.  
  166. SHORT
  167. change_project_screen(VOID)
  168. {
  169.     struct GadgetData *gd = &screen_gadget_data[0];
  170.     APTR gl;
  171.     SHORT status;
  172.  
  173.     /* Init gadgets with current values */
  174.     (gd + SCREEN_GADGET_LEFTEDGE)->gd_SpecialData.gd_InputData.gd_InputDefault = (VOID *) editor_new_screen.LeftEdge;
  175.     (gd + SCREEN_GADGET_TOPEDGE)->gd_SpecialData.gd_InputData.gd_InputDefault = (VOID *) editor_new_screen.TopEdge;
  176.     (gd + SCREEN_GADGET_WIDTH)->gd_SpecialData.gd_InputData.gd_InputDefault = (VOID *) editor_new_screen.Width;
  177.     (gd + SCREEN_GADGET_HEIGHT)->gd_SpecialData.gd_InputData.gd_InputDefault = (VOID *) editor_new_screen.Height;
  178.     (gd + SCREEN_GADGET_DETAILPEN)->gd_SpecialData.gd_InputData.gd_InputDefault = (VOID *) editor_new_screen.DetailPen;
  179.     (gd + SCREEN_GADGET_BLOCKPEN)->gd_SpecialData.gd_InputData.gd_InputDefault = (VOID *) editor_new_screen.BlockPen;
  180.     (gd + SCREEN_GADGET_TITLE)->gd_SpecialData.gd_InputData.gd_InputDefault = (BYTE *) editor_new_screen.DefaultTitle;
  181.  
  182.     (gd + SCREEN_GADGET_HIRES)->gd_SpecialData.gd_CheckData.gd_CheckSelected = (ULONG) (editor_new_screen.ViewModes & HIRES ? 1 : 0);
  183.     (gd + SCREEN_GADGET_INTERLACE)->gd_SpecialData.gd_CheckData.gd_CheckSelected = (ULONG) (editor_new_screen.ViewModes & INTERLACE ? 1 : 0);
  184.     (gd + SCREEN_GADGET_SPRITES)->gd_SpecialData.gd_CheckData.gd_CheckSelected = (ULONG) (editor_new_screen.ViewModes & SPRITES ? 1 : 0);
  185.     (gd + SCREEN_GADGET_DUALPF)->gd_SpecialData.gd_CheckData.gd_CheckSelected = (ULONG) (editor_new_screen.ViewModes & DUALPF ? 1 : 0);
  186.     (gd + SCREEN_GADGET_HAM)->gd_SpecialData.gd_CheckData.gd_CheckSelected = (ULONG) (editor_new_screen.ViewModes & HAM ? 1 : 0);
  187.  
  188.     (gd + SCREEN_GADGET_SCREENTYPE)->gd_SpecialData.gd_MXData.gd_MXActiveEntry = (ULONG) editor_screen_type;
  189.  
  190.     /* Print title and display gadgets */
  191.     IClearWindow(eri, ewin, 0, 0, EDITOR_WINDOW_WIDTH, EDITOR_WINDOW_HEIGHT, 0);
  192.  
  193.     if (!(gl = ICreateGadgets(eri, &screen_gadget_data[0], 0, 0, NULL)))
  194.         status = EDITOR_ERROR_OUT_OF_MEM;
  195.     else
  196.     {
  197.         /* Init IDCMPFlag and Flag list */
  198.  
  199.         IDisplayGadgets(ewin, gl);
  200.         status = change_project_screen_action(gl);
  201.         IRemoveGadgets(gl);
  202.         IFreeGadgets(gl);
  203.     }
  204.  
  205.     return (status);
  206. }
  207.  
  208. STATIC SHORT
  209. change_project_screen_action(APTR gl)
  210. {
  211.     struct MsgPort *up = ewin->UserPort;
  212.     BOOL keepon = TRUE;
  213.  
  214.     do
  215.     {
  216.         struct IntuiMessage *msg;
  217.  
  218.         WaitPort(up);
  219.         while (msg = IGetMsg(up))
  220.         {
  221.             ULONG Class = msg->Class;
  222.             USHORT Code = msg->Code;
  223.             LONG IAddress = (LONG) msg->IAddress;
  224.  
  225.             switch (Class)
  226.             {
  227.             case CLOSEWINDOW:
  228.                 keepon = FALSE;
  229.                 break;
  230.  
  231.             case ISUP_ID:
  232.                 switch (Code)
  233.                 {
  234.                 case SCREEN_GADGET_LEFTEDGE:
  235.                     printf("SCREEN_GADGET_LEFTEDGE: %ld\n", IAddress);
  236.                     break;
  237.  
  238.                 case SCREEN_GADGET_TOPEDGE:
  239.                     printf("SCREEN_GADGET_TOPEDGE: %ld\n", IAddress);
  240.                     editor_new_screen.TopEdge = (SHORT) IAddress;
  241.                     break;
  242.  
  243.                 case SCREEN_GADGET_WIDTH:
  244.                     printf("SCREEN_GADGET_WIDTH: %ld\n", IAddress);
  245.                     editor_new_screen.Width = (SHORT) IAddress;
  246.                     break;
  247.  
  248.                 case SCREEN_GADGET_HEIGHT:
  249.                     printf("SCREEN_GADGET_HEIGHT: %ld\n", IAddress);
  250.                     editor_new_screen.Height = (SHORT) IAddress;
  251.                     break;
  252.  
  253.                 case SCREEN_GADGET_DEPTH:
  254.                     printf("SCREEN_GADGET_DEPTH: %ld\n", IAddress);
  255.                     editor_new_screen.Depth = (SHORT) IAddress;
  256.                     break;
  257.  
  258.                 case SCREEN_GADGET_DETAILPEN:
  259.                     printf("SCREEN_GADGET_DETAILPEN: %ld\n", IAddress);
  260.                     editor_new_screen.DetailPen = (UBYTE) IAddress;
  261.                     break;
  262.  
  263.                 case SCREEN_GADGET_BLOCKPEN:
  264.                     printf("SCREEN_GADGET_BLOCKPEN: %ld\n", IAddress);
  265.                     editor_new_screen.BlockPen = (UBYTE) IAddress;
  266.                     break;
  267.  
  268.                 case SCREEN_GADGET_INTERLACE:
  269.                     printf("SCREEN_GADGET_INTERLACE: %ld\n", IAddress);
  270.                     if (IAddress)
  271.                         editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes | INTERLACE;
  272.                     else
  273.                         editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes ^ INTERLACE;
  274.                     break;
  275.  
  276.                 case SCREEN_GADGET_SPRITES:
  277.                     printf("SCREEN_GADGET_SPRITES: %ld\n", IAddress);
  278.                     if (IAddress)
  279.                         editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes | SPRITES;
  280.                     else
  281.                         editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes ^ SPRITES;
  282.                     break;
  283.  
  284.                 case SCREEN_GADGET_DUALPF:
  285.                     printf("SCREEN_GADGET_DUALPF: %ld\n", IAddress);
  286.                     if (IAddress)
  287.                     {
  288.                         if ((editor_new_screen.ViewModes & HIRES) || (editor_new_screen.ViewModes & HAM))
  289.                         {
  290.                             printf("Hires, Ham and Dualpf not allowed at the same time\n");
  291.                             ISetGadgetAttributes(gl, SCREEN_GADGET_DUALPF, 0L, 0L, 0L, 0L, (VOID *) 0);
  292.                         }
  293.                         else
  294.                             editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes | DUALPF;
  295.                     }
  296.                     else
  297.                         editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes ^ DUALPF;
  298.                     break;
  299.  
  300.                 case SCREEN_GADGET_HIRES:
  301.                     printf("SCREEN_GADGET_HIRES: %ld\n", IAddress);
  302.                     if (IAddress)
  303.                     {
  304.                         if ((editor_new_screen.ViewModes & DUALPF) || (editor_new_screen.ViewModes & HAM))
  305.                         {
  306.                             printf("Hires, Ham and Dualpf not allowed at the same time\n");
  307.                             ISetGadgetAttributes(gl, SCREEN_GADGET_HIRES, 0L, 0L, 0L, 0L, (VOID *) 0);
  308.                         }
  309.                         else
  310.                             editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes | HIRES;
  311.                     }
  312.                     else
  313.                         editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes ^ HIRES;
  314.                     break;
  315.  
  316.                 case SCREEN_GADGET_HAM:
  317.                     printf("SCREEN_GADGET_HAM: %ld\n", IAddress);
  318.                     if (IAddress)
  319.                     {
  320.                         if ((editor_new_screen.ViewModes & HIRES) || (editor_new_screen.ViewModes & DUALPF))
  321.                         {
  322.                             printf("Hires, Ham and Dualpf not allowed at the same time\n");
  323.                             ISetGadgetAttributes(gl, SCREEN_GADGET_HAM, 0L, 0L, 0L, 0L, (VOID *) 0);
  324.                         }
  325.                         else
  326.                             editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes | HAM;
  327.                     }
  328.                     else
  329.                         editor_new_screen.ViewModes = (USHORT) editor_new_screen.ViewModes ^ HAM;
  330.                     break;
  331.  
  332.                 case SCREEN_GADGET_TITLE:
  333.                     printf("SCREEN_GADGET_TITLE: %s\n", IAddress);
  334.                     sprintf((BYTE *) editor_new_screen.DefaultTitle, "%s", IAddress);
  335.                     break;
  336.  
  337.                 case SCREEN_GADGET_SCREENTYPE:
  338.                     printf("SCREEN_GADGET_SCREENTYPE: %ld\n", IAddress);
  339.                     switch ((USHORT) IAddress)
  340.                     {
  341.                     case EDITOR_SCREEN_TYPE_WBENCH:
  342.                         editor_screen_type = EDITOR_SCREEN_TYPE_WBENCH;
  343.                         break;
  344.                     case EDITOR_SCREEN_TYPE_CUSTOM:
  345.                         editor_screen_type = EDITOR_SCREEN_TYPE_CUSTOM;
  346.                         break;
  347.                     case EDITOR_SCREEN_TYPE_BITMAP:
  348.                         editor_screen_type = EDITOR_SCREEN_TYPE_BITMAP;
  349.                         break;
  350.                     }
  351.                     break;
  352.  
  353.                 case SCREEN_GADGET_OK:
  354. /*
  355.                                                                                                                 if( (screen=(struct Screen*)OpenScreen(&editor_new_screen))==NULL)
  356.                                                                                                                                 printf("Couldn't open screen\n");
  357.                                                                                                                 else
  358.                                                                                                                 {
  359.                                                                                                                                 Delay(200);
  360.                                                                                                                                 CloseScreen(screen);
  361.                                                                                                                 }
  362. */
  363.                     keepon = FALSE;
  364.                     break;
  365.  
  366.                 case SCREEN_GADGET_CANCEL:
  367.                     keepon = FALSE;
  368.                     break;
  369.                 }
  370.             }
  371.  
  372.             IReplyMsg(msg);
  373.         }
  374.     }
  375.     while (keepon == TRUE);
  376.  
  377.     return EDITOR_STATUS_NORMAL;
  378. }
  379.